<?php
/***
 * 创作启动蒙板
 *
 *
 * @author    lanhongjie <lanhj@yunys.com.cn>
 * @copyright 2016 QuanZhouYunYiShang Inc.
 */

namespace App\Services\ProdTempCreationMasksService;


use App\Services\ImgServices\ImgTool;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class CreationMaskApiService
{
    /***
     * 分页获取创作启动模板
     * @param int $per_page
     * @return mixed
     */
    public function getCreationMasks($per_page=6){
        if(!is_int($per_page)||($per_page)<1){
            $per_page=6;
        }
        $creation_masks=DB::table('creation_masks')
            ->where(array('state'=>1,'is_show'=>1))
            ->orderBy('sort','ASC')
            ->select('name','product_temp_category_id','product_temp_id','original_image')
            ->paginate($per_page);
        foreach ($creation_masks as $creation_mask){
            if(!empty($creation_mask->original_image)){
                $original_image=ImgTool::getImgUrlByImgPath($creation_mask->original_image);
                $creation_mask->original_image=empty($original_image)?'':$original_image;
            }
        }
        $creation_masks=$creation_masks->toArray();
        if(empty($creation_masks['data'])){
            return array('data' => array(), 'current_page' => 1,
                'per_page' => $creation_masks['per_page'], 'total_page' => 0,
                'total' => 0);
        }
        return array('data' => $creation_masks['data'], 'current_page' => $creation_masks['current_page'],
            'per_page' => $creation_masks['per_page'], 'total_page' => $creation_masks['last_page'],
            'total' => $creation_masks['total']);
    }

}